/*
 * @Author: your name
 * @Date: 2021-01-12 12:36:05
 * @LastEditTime: 2021-01-20 17:58:45
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \myReposCode\transfer.cpp
 */

#include <algorithm>
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

template <class T1, class T2> void transfer(const T1 &t1, T2 &t2) {
    std::stringstream sstream;
    sstream << t1;
    sstream >> t2;
}

int TestFunc(int a, char c, float f) {
    std::cout << a << std::endl;
    std::cout << c << std::endl;
    std::cout << f << std::endl;
    return a;
}

auto fun1 = std::bind(TestFunc, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
// func2 占位符->第二个参数和函数第一个参数匹配（int）,第三个参数和第二个参数匹配（char）,第一个参数和第三个参数匹配  
auto fun2 = std::bind(TestFunc, std::placeholders::_2, std::placeholders::_3, std::placeholders::_1);
auto fun3 = std::bind(TestFunc, std::placeholders::_1, std::placeholders::_2, 98.77);

int main() {
    auto lambda1 = [] { std::cout << "Hello, World!\n"; };
    std::vector<int> numbers{1, 2, 3, 4, 5, 10, 15, 20, 25, 35, 45, 50};
    auto lambdaFunc = [](int i, int min, int max) {
        if (i >= min && i < max) {
            cout << i << " ";
        }
    };
    std::function<void(int)> bdLF = std::bind(lambdaFunc, std::placeholders::_1, 3, 36);
    std::for_each(numbers.begin(), numbers.end(), bdLF);
    cout << endl;
    std::string str("1.5");
    double value = 0;
    transfer<std::string, double>(str, value);
    std::cout << "value = " << value << std::endl;

    fun2(100.1, 30, 'c');

    return 0;
}